package com.example.po;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import lombok.Data;

import java.util.Date;

@Data
@TableName(value = "sys_job")
public class SysJob extends Model<SysJob> {

    @TableId(type = IdType.ASSIGN_ID)
    private Long id;

    //任务类型
    @TableField(value = "type")
    private String type;

    //服务节点
    @TableField(value = "server_key")
    private Long serverKey;

    //处理对象
    @TableField(value = "target")
    private String target;

    //正文内容
    @TableField(value = "context")
    private String context;

    //重试次数
    @TableField(value = "retry_count")
    private int retryCount;

    //下次重试时间
    @TableField(value = "retry_time")
    private Date retryTime;

    //任务状态
    @TableField(value = "status")
    private int status;

    //任务优先级
    @TableField(value = "priority")
    private int priority;

    //创建时间
    @TableField(value = "create_time")
    private Date createTime;

    //更新时间
    @TableField(value = "update_time")
    private Date updateTime;

    public void recalculateFields() {
        if (this.createTime == null) {
            this.createTime = new Date();
        }
        this.updateTime = new Date();
    }
}
